package io.adrainty.algorithm.leetcode.lcr;

/**
 * LCR 004. 只出现一次的数字 II
 * @link <a href="https://leetcode.cn/problems/WGki4K/">...</a>
 * @author AdRainty
 * @version V1.0.0
 * @since 2024/9/1 上午12:27
 */
public class LCR004 {

    public int singleNumber(int[] nums) {
        int[] byteSums = new int[32];
        for (int num : nums) {
            for (int i = 0; i < 32; i++) {
                // (num >> (31 - i)) & 1 得到整数num的二进制形式中的第i位数位
                // 相当于先把i放到最右边 然后跟00000001做与
                byteSums[i] += (num >> (31 - i)) & 1;
            }
        }
        int res = 0;
        for (int i = 0; i < 32; i++) {
            res = (res << 1) + byteSums[i] % 3;
        }
        return res;
    }

}
